#!/usr/bin/env python
#coding:utf-8
#
# generate top upers
#
from include import common

def topuper():
	c = common.getdb().cursor()
	c.execute('''select uid from (ac_threads left join ac_stats using (id)) 
                group by uid order by sum(clicks+avclicks) desc''')
	rank = 1
	for x in c.fetchall():
		uid = x[0]
		if not uid:
			continue
		c.execute('select * from acu_infos where uid=%s',(uid,))
		if not c.fetchone():
			c.execute('''insert into acu_infos 
				(uid,sex,location,dateofbirth,interests,brief,signature)
				values (%s,'','','1900-01-01','','','')''',(uid,))
		c.execute('update acu_infos set rank=%s where uid=%s',(rank,uid))
		rank += 1

if __name__ == '__main__':
	topuper()
	common.removeall('data/userrank')
